package com.study.hm;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author study
 * @version 1.0
 * @date 2020/9/26 14:57
 */
public class RunnableImpl implements Runnable {
    Lock lock = new ReentrantLock();
    private int ticket = 100;

    @Override
    public void run() {
        while (true) {
            lock.lock();

            try {
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName() + "卖出" + ticket);
                    ticket--;
                } else {
                    break;
                }
            } finally {
                lock.unlock();
            }
        }
    }
}
